package com.cskaoyan.service;

import com.cskaoyan.bean.RegionListVO;
import com.cskaoyan.mapper.RegionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements RegionService {

    @Autowired
    RegionMapper regionMapper;

    @Override
    public List<RegionListVO> allRegion() {
        List<RegionListVO> regionVOList = regionMapper.getRegionByPid(0);
        for (RegionListVO regionVO : regionVOList) {
            regionVO.setChildren(regionMapper.getRegionByPid(regionVO.getId()));
            for (RegionListVO child : regionVO.getChildren()) {
                child.setChildren(regionMapper.getRegionByPid(child.getId()));
            }
        }
        return regionVOList;
    }
}
